package cate.common.table.activity.newlimitshop.daily_base;

import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import easy.java.dev.note.NoteField;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@EExcelRowClass
public class NewLimitShopDailyBaseRow extends ERow {
    @EExcelNoteField(fieldName = "功能ID")
    public int funcId;
    @EExcelNoteField(fieldName = "配置ID")
    public int configId;
    @EExcelNoteField(fieldName = "分组ID")
    public int group;
    @EExcelNoteField(fieldName = "页签分组ID")
    public int tag;
    @EExcelNoteField(fieldName = "重置类型", defaultValue = "0")
    public int resetType;
    @EExcelNoteField(fieldName = "全买解锁条件")
    public String extraConditionStr;
    @EExcelNoteField(fieldName = "全买奖励")
    public String extraRewardStr;
    @EExcelNoteField(fieldName = "一键购买支付项ID", defaultValue = "0")
    public int payItemId;

    @NoteField("商品ID -> 购买数量")
    public Map<Integer, Integer> extraItemCons = new HashMap<>();

    @Override
    public void decode() {
        super.decode();
        extraItemCons.clear();
        if (!StringUtils.isEmpty(extraConditionStr)) {
            try {
                String[] sp1 = extraConditionStr.split("#");
                for (String str : sp1) {
                    String[] sp2 = str.split(":");
                    extraItemCons.put(Integer.parseInt(sp2[0]), Integer.parseInt(sp2[1]));
                }
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }

    /**
     * 是否有额外奖励
     */
    public boolean extraExists() {
        return !StringUtils.isEmpty(extraRewardStr) && !extraItemCons.isEmpty();
    }
}
